import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDPayItemProduct {
	/**id*/
	id,
	/**渠道id--0：ios--1：谷歌--1019:酷派--1012：联想--1024：三星--1287：木子时代--1289：蜂果盒子*/
	channel,
	/**支付id*/
	productid,
	/**充值金额*/
	rmb,

	/**枚举数量*/
	EnumCount
}



export class CDPayItemProduct{
	/**id*/
	public id: number;
	/**渠道id--0：ios--1：谷歌--1019:酷派--1012：联想--1024：三星--1287：木子时代--1289：蜂果盒子*/
	public channel: string;
	/**支付id*/
	public productid: number;
	/**充值金额*/
	public rmb: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDPayItemProduct.id: return this.id;
			case E_CDPayItemProduct.channel: return this.channel;
			case E_CDPayItemProduct.productid: return this.productid;
			case E_CDPayItemProduct.rmb: return this.rmb;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDPayItemProduct.id: this.id = v; break;
			case E_CDPayItemProduct.channel: this.channel = v; break;
			case E_CDPayItemProduct.productid: this.productid = v; break;
			case E_CDPayItemProduct.rmb: this.rmb = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDPayItemProduct> = new HashMap<number, CDPayItemProduct>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDPayItemProduct[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDPayItemProduct();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].channel = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].productid = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].rmb = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDPayItemProduct{
		return this.datas ? this.datas.get(id) : null;
	}
}
